
package com.gp.activity.main;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;

import com.gp.R;

/**
 * @author shijunxing
 * @className AppStartActivity
 * @date Sep 6, 2013 1:33:04 PM
 * @version 1.0
 * @Description 应用程序启动类：显示欢迎界面并跳转到主界面
 */
public class AppStartActivity extends Activity {

    // 是否是第一次使用
    private boolean isFirstUse;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        final View view = View.inflate(this, R.layout.app_start, null);
        setContentView(view);

        // 渐变展示启动屏
        AlphaAnimation qAlphaAnimation = new AlphaAnimation(0.3f, 1.0f);
        qAlphaAnimation.setDuration(2000);
        view.startAnimation(qAlphaAnimation);
        qAlphaAnimation.setAnimationListener(new AnimationListener() {
            @SuppressWarnings("deprecation")
            @Override
            public void onAnimationEnd(Animation arg0) {
                // 读取SharedPreferences中需要的数据
                SharedPreferences preferences = getSharedPreferences(
                        "isFirstUse", MODE_WORLD_READABLE);
                isFirstUse = preferences.getBoolean("isFirstUse", true);
                //如果第一次启动
                if (isFirstUse) {
                    toNavigation();
                }else {
                    toMain();
                }

                // 实例化Editor对象
                Editor editor = preferences.edit();
                // 存入数据
                editor.putBoolean("isFirstUse", false);
                // 提交修改
                editor.commit();
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
            }

            @Override
            public void onAnimationStart(Animation animation) {
            }

        });

    }

    /**
     * 跳转到...
     */
    private void toNavigation() {
        Intent intent = new Intent(this, NavigationActivity.class);
        startActivity(intent);
        finish();
    }

    private void toMain() {
        Intent intent = new Intent(this, MainActivity.class);
        startActivity(intent);
        finish();
    }
}
